﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;

namespace Taxes.Users
{
    public partial class ChangePwd : System.Web.UI.Page
    {
        Model.ysys_user userInfo;
        protected void Page_Load(object sender, EventArgs e)
        {
            userInfo = Session["curr_user"] as Model.ysys_user;

        }

        protected void btnSave_Click(object sender, DirectEventArgs e)
        {
            if (TF_OldPwd.Text.Trim() == string.Empty)
            {
                X.MessageBox.Configure(new MessageBoxConfig()
                {
                    Icon = MessageBox.Icon.INFO,
                    Title = "提示",
                    Message = "旧密码不能为空"
                }).Show();
                return;
            }
            if (TF_Pwd.Text.Trim() == string.Empty)
            {
                X.MessageBox.Configure(new MessageBoxConfig()
                {
                    Icon = MessageBox.Icon.INFO,
                    Title = "提示",
                    Message = "新密码不能为空"
                }).Show();
                return;
            }
            if (TF_ConPwd.Text.Trim() != TF_Pwd.Text.Trim())
            {
                X.MessageBox.Configure(new MessageBoxConfig()
                {
                    Icon = MessageBox.Icon.INFO,
                    Title = "提示",
                    Message = "确认密码必须与新密码一致",
                    Buttons = MessageBox.Button.OK
                }).Show();
                return;
            }
            if (TF_OldPwd.Text.Trim() != userInfo.user_pwd)
            {
                X.MessageBox.Configure(new MessageBoxConfig()
                {
                    Icon = MessageBox.Icon.INFO,
                    Title = "提示",
                    Message = "旧密码输入不正确",
                    Buttons = MessageBox.Button.OK
                }).Show();
                return;
            }

            var bll = new BLL.ysys_user();
            if (bll.UpdatePwd(userInfo.user_name, TF_Pwd.Text.Trim()))
            {
                X.MessageBox.Configure(new MessageBoxConfig()
                {
                    Icon = MessageBox.Icon.INFO,
                    Title = "提示",
                    Message = "修改成功",
                    Buttons = MessageBox.Button.OK
                }).Show();

                userInfo.user_pwd = TF_Pwd.Text.Trim();
                TF_OldPwd.Text = "";
                TF_Pwd.Text = "";
                TF_ConPwd.Text = "";
                Session["curr_user"] = userInfo;
                Response.Redirect("");
            }
            else
            {
                X.MessageBox.Configure(new MessageBoxConfig()
                {
                    Icon = MessageBox.Icon.INFO,
                    Title = "提示",
                    Message = "修改失败请重试",
                    Buttons = MessageBox.Button.OK
                }).Show();
            }
        }
    }
}